package com.demo.core.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.demo.core.dao.MemberRoleDao;
import com.demo.core.dao.impl.base.PageCoreDaoSupport;
import com.demo.core.model.MemberRole;
import com.demo.core.model.Role;
import com.demo.core.model.support.GeneralExecuteModel;

/**
 * 会员角色数据访问层实现类
 * 
 * @author ryuu.kk
 */
public class MemberRoleDaoImpl extends PageCoreDaoSupport<MemberRole, Long> implements MemberRoleDao {
	/**
	 * 会员角色空间 
	 */
	protected final static String MEMBER_ROLE_SPACE = "memberRoleSpace.";
	/**
	 * 模型表名
	 */
	protected final static String TABLE_NAME = "T_CORE_MEMBER_ROLE";
	/**
	 * 模型表主键ID
	 */
	protected final static String TABLE_PK_NAME = "ID";
	
	@Override
	public int updateEnabled(Long id, boolean enabled) {
		cacheClear();
		Map<String, Object> params = new HashMap<String, Object>();
		MemberRole rm = new MemberRole();
		rm.setEnabled(enabled);
		params.put("id", id);
		return super.update(rm, params);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Role> queryRole(Map<String, Object> params) {
		return getSqlMapClientTemplate().queryForList(nameSpace() + "queryRole", params);
	}

	@Override
	protected String nameSpace() {
		return MEMBER_ROLE_SPACE;
	}
	@Override
	protected void doInit(GeneralExecuteModel<Long> model) {
		model.setPk(TABLE_PK_NAME);
		model.setTable(TABLE_NAME);
	}
}
